//
//  ConsultListService.m
//  homeland
//
//  Created by caesar on 14-8-4.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//

#import "ConsultListService.h"
#import "UserInfoService.h"
#import "WaiterConsult.h"
#import "ConsultListCellTableViewCell.h"

@implementation ConsultListService

-(id)init
{
    self = [super init];
    if (self) {
        _dataItemName = @"WaiterConsult";
    }
    return self;
}

//加载第一页数据
- (void)loadDataWithKey:(NSString *)keyOrNil{
    _currentPageNo = 1;
    if (self.dataList) {
        self.dataList = nil;
    }
    _dataItemName = @"WaiterConsult";
    NSDictionary *_config = [super paramDic];
    
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    // institutionId partyParentId partyName()
    [params setValue:[_config objectForKey:@"uid"] forKey:@"uid"];
    [params setValue:[_config objectForKey:[UserInfoService getUserInfoService].userInfo.Id] forKey:@"userId"];
 
    [self doHttpPost:SERVER_URL_COMMUNITY_WAITER_CONSULT_LIST headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo] parameters:params];
}
//加载更多数据
- (void)loadMoreDataWithKey:(NSString *)keyOrNil{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSDictionary *_config = [super paramDic];
    [params setValue:[_config objectForKey:@"uid"] forKey:@"uid"];
    [params setValue:[_config objectForKey:[UserInfoService getUserInfoService].userInfo.Id] forKey:@"userId"];
 
    
    _dataItemName = @"WaiterConsult";
    [self doHttpPost:SERVER_URL_COMMUNITY_WAITER_CONSULT_LIST headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo + 1] parameters:params];
}

- (CGFloat)heightForCellAtRow:(NSIndexPath *)index{
    return 44.0f;//民意征集/我要投票每行105
}

/**展示数据*/
- (void)configCell:(UITableViewCell *)cell atIndex:(NSIndexPath *)index{
    if (self.dataList == nil || self.dataList.count == 0) {
        return;
    }
    //民意征集/我要投票
    WaiterConsult *item = [self.dataList objectAtIndex:index.row];
    ConsultListCellTableViewCell *tempCell = (ConsultListCellTableViewCell *)cell;
   
    tempCell.titleLble.text = item.title;
    NSString *state;
    if (!item.replyStatus || item.replyStatus.length == 0 || [item.replyStatus isEqualToString:@"0"]) {
        state = @"未回复";
    }else{
        state = @"已回复";
    }
    
    tempCell.stateLable.text = state;

}
-(NSDictionary *)getTargetConfigForCellAtIndex:(NSIndexPath *)indexPath
{
    
    if (self.dataList == nil || self.dataList.count == 0) {
        return nil;
    }
    WaiterConsult *item = [self.dataList objectAtIndex:indexPath.row];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"key",item,@"dataItem", nil];
    return dic;
}
@end
